<template>
  <div class="playlist-container">
    <div class="top-wrap">
      <div class="img-wrap">
        <!-- 封面  -->
        <img :src="playlist.coverImgUrl" alt="" />
      </div>
      <!-- 标题和头像的区域 -->
      <div class="info-wrap">
        <p class="title">{{playlist.name}}</p>
        <div class="author-wrap">
          <img class="avatar" :src="this.playlist.creator.avatarUrl" alt="" />
          <span class="name">{{playlist.creator.nickname}}</span>
          <span class="time">{{playlist.createTime}} 创建</span>
        </div>
        <div class="play-wrap">
          <span class="iconfont icon-circle-play"></span>
          <span class="text">播放全部</span>
        </div>
        <!-- 标签的区域 -->
        <div class="tag-wrap" v-if="playlist.tags.length!==0">
          <span class="title" >标签:</span>
          <ul >
            <li v-for="(item,idnex) in playlist.tags" :key="idnex">{{item}}</li>

          </ul>
        </div>
        <!-- 简介的区域 -->
        <div class="desc-wrap">
          <span class="title">简介:</span>
          <span class="desc"
            >{{playlist.description}}</span
          >
        </div>
      </div>
    </div>
    <el-tabs v-model="activeIndex">
      <el-tab-pane label="歌曲列表" name="1">
        <table class="el-table playlit-table">
          <thead>
            <th></th>
            <th></th>
            <th>音乐标题</th>
            <th>歌手</th>
            <th>专辑</th>
            <th>时长</th>
          </thead>
          <tbody>
            <tr
            style="cursor:pointer"
            class="el-table__row" @click="playAudio(item.id)" v-for="(item,index) in playlist.tracks" :key="index">
              <td>{{index+1}}</td>
              <td>
                <div class="img-wrap">
                  <img :src="item.al.picUrl" alt="" />
                  <span v-if="item.mv!==''" class="iconfont icon-play"></span>
                </div>
              </td>
              <td>
                <div class="song-wrap">
                  <div class="name-wrap">
                    <span>{{item.name}}</span>
                    <span class="iconfont icon-mv"></span>
                  </div>
                  <span></span>
                </div>
              </td>
              <td>{{item.ar[0].name}}</td>
              <td>{{item.name}}</td>
              <td>{{item.dt|time}}</td>
            </tr>

          </tbody>
        </table>
      </el-tab-pane>
      <el-tab-pane :label="`评论(${this.total+this.totals})`" name="2">
        <!-- 精彩评论 -->
        <div class="comment-wrap">
          <p class="title">精彩评论<span class="number">({{totals}})</span></p>
          <div class="comments-wrap">
            <div class="item" v-for="(item,index) in hotComment" :key="index">
              <div class="icon-wrap">
                <img :src="item.user.avatarUrl" alt="" />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{item.user.nickname}}:</span>
                  <span class="comment">{{item.content}}</span>
                </div>
                <div class="re-content" v-if="item.beReplied.length!==0">
                  <span class="name">小苹果：</span>
                  <span class="comment">还是小时候比较可爱</span>
                </div>
                <div class="date">{{item.time|timeShow}}</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 最新评论 -->
        <div class="comment-wrap">
          <p class="title">最新评论<span class="number">({{total}})</span></p>
          <div class="comments-wrap">
            <div class="item" v-for="(item,index) in comment" :key="index">
              <div class="icon-wrap">
                <img :src="item.user.avatarUrl" alt="" />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{item.user.nickname}}：</span>
                  <span class="comment">{{item.content}}</span>
                </div>
                <div class="re-content" v-if="item.beReplied.length!==0" >
                  <span class="name">{{item.beReplied[0].user.nickname}}:</span>
                  <span class="comment">{{item.beReplied[0].content}}</span>
                </div>
                <div class="date">{{item.time|timeShow}}</div>
              </div>
            </div>

          </div>
        </div>
        <!-- 分页器 -->
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="10"
        >
        </el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {getMenu,getData,getNewData} from '@/api/detail'
import {getLunBoMusic} from '@/api/getMusic'
export default {
  name: 'playlist',
  data() {
    return {
      activeIndex: '1',
      // 总条数
      total: 0,
      // 页码
      page: 1,
      // 保存数据
      playlist:{},
      dataList:[],
      //热门评论
      hotComment:[],
      //评论总数
      totals:0,
      comment:[],
      totald:0,
      offset:0
    };
  },
  created() {
    this.getMenu()
    this.getData()
    this.getNewData()
  },
  methods: {
      // 点击播放歌曲
      async playAudio(id){

      //  发送请求获取url地址
      const {data:{data}}=await
      getLunBoMusic(id)
      // 进行判断是否有url的值
      if(data[0].url){
        // 将当前的id保存到数组中
        this.$store.commit('getId',id)
        // 播放歌曲
       this.$store.commit('getUrl',data[0].url)
       return
      }
      this.$message.warning('没有版权,暂无法播放')

      },
    // 获取最新评论的数据
    async getNewData(){
      const {data}=await getNewData({
        id:this.$route.query.id,
        limit:10,
        offset:this.offset
      })
      this.comment=data.comments
      this.total=data.total

    },
    // 获取评论列表的数据
    async getData(){
      const {data}=await getData({
        id:this.$route.query.id,
        type:2
      })
      this.hotComment=data.hotComments
      this.totals=data.total

    },
    // 获取歌单列表数据
    async getMenu(){
      const {data}=await getMenu(this.$route.query.id)
      this.playlist=data.playlist
      console.log(data);
      this.$store.commit('getArr',data.playlist.trackIds)
    },
    // 点击页面进行切换
    handleCurrentChange(val) {
     this.page=val
     this.offset=(this.page-1)*10
      //  发送请求
      this.getNewData()
    }
  }
};
</script>

<style >

</style>
